package com.onclick.webchat.websocket;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;

public class HandShakes implements HandshakeInterceptor {

	@Override
	public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler arg2, Exception arg3) {
	
	}

	@Override
	public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler arg2,
			Map<String, Object> arg3) throws Exception {
		if (request instanceof ServletServerHttpRequest) {
			ServletServerHttpRequest servlet = (ServletServerHttpRequest) request;
			HttpSession session = servlet.getServletRequest().getSession(false);
			String string=(String) session.getAttribute("privateId");
			System.out.println(string);
			Boolean flag = string == null?false:true;
			if (flag) {
				arg3.put("privateId", string);
				
				return flag;
			}else {
				return flag;
			}
		}else
		
		return false;
	}

}
